/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vm;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Peer
 */
public class MemoryTableModel extends AbstractTableModel {

    HashMap<Integer,Integer> data;
    Set<Integer> dataset;
    Integer[] tmp;

    public int getRowCount() {
        return 1;
    }

    public int getColumnCount() {
        if(data!=null)
            return data.size();
        else
            return 0;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        return data.get(tmp[columnIndex]);
    }

    @Override
    public String getColumnName(int column) {
        return Integer.toString(tmp[column]);
    }

    @Override
    public void fireTableStructureChanged() {
        tmp = (dataset.toArray(new Integer[0]));
        Arrays.sort(tmp);
        super.fireTableStructureChanged();
    }



    public void setData(HashMap<Integer,Integer> data) {
        this.data = data;
        this.dataset = data.keySet();
    }

}
